﻿Imports SS
Imports SS.Databases
Imports SS.Databases.Connecter
Imports SS.ApplicationBlock

Public Class IVRFile

	Private OraConn As DBOracle
	Dim strSchema As String

	Public Sub New()
		OraConn = New DBOracle(Common.Utility.ConnectString, True, DBOracle.ModeConnection.OracleClient)
		strSchema = Common.Utility.Schema
	End Sub

	Public Function Insert(ByVal item As Entity.IVRFileItem) As Boolean
		Dim strSql As String
		strSql = ORM.Broker.RetrieveInsert(item, strSchema & ".RNWT_LOG_IVRFTP_FILE").Replace("VALUES ('0'", "VALUES (" & strSchema & ".RNW_SEQ_IVRXML_FILE.NEXTVAL")
		If OraConn.ExecuteNonQuery(strSql) = 1 Then
			Return True
		Else
			Return False
		End If
	End Function

	Public Sub UpdateFlage(ByVal flagId As String, ByVal fileName As String)
		OraConn.ExecuteNonQuery("UPDATE " & strSchema & ".RNWT_LOG_IVRFTP_FILE SET RECORD_STATUS = 'I' WHERE IVR_FILE_NAME ='" & fileName & "'")
	End Sub

	Public Shared Function InsertLog(ByVal fileName As String, ByVal item As String, ByVal result As String) As Boolean
		Dim sb As New Text.StringBuilder
		sb.AppendLine("INSERT INTO RNWT_SUM_IVR_FILE (CAL_DATE,FILE_NAME,ITEMS,RESULT) VALUES ")
		sb.AppendLine(" ( ")
		sb.AppendLine("sysdate,")
		sb.AppendLine("'" & fileName & "',")
		sb.AppendLine("'" & item & "',")
		sb.AppendLine("'" & result & "'")
		sb.AppendLine(" ) ")
		Dim OraConnLog = New DBOracle(Common.Utility.ConnectString, False, DBOracle.ModeConnection.OracleClient)
		If OraConnLog.ExecuteNonQuery(sb.ToString) = 1 Then
			Return True
		Else
			Return False
		End If
	End Function

	Public Sub Close()
		OraConn.Close()
	End Sub

	Public Sub Commit()
		OraConn.Commit()
	End Sub

	Public Sub Rollback()
		OraConn.Rollback()
	End Sub

End Class
